import { Http } from '@/utils';

export async function fetchDetail(params: {}) {
  const { errorCode, data } = await Http({
    url: '/house/detail',
    params,
  });

  if (errorCode === 0) {
    return data;
  }
  return null;
}

export async function fetchComments(params: {}) {
  const { houseId, ...rest } = params as any;
  const { errorCode, data } = await Http(
    {
      url: `/house/${houseId}/comments`,
      params: rest,
    },
    false,
  );
  if (errorCode === 0) {
    return data;
  }
  return [];
}

export async function fetchAddComments(payload: { houseId: string | number }) {
  const { houseId, ...rest } = payload;
  const ret = await Http(
    {
      url: `/house/${houseId}/comments/add`,
      method: 'POST',
      data: rest,
    },
    false,
  );

  return ret;
}
